import { App } from 'antd'
import { autoLoginAPI } from '@/apis'
import { useNavigate , useSearchParams  } from 'react-router-dom'
export default function AutoLogin() {
    const {message} = App.useApp()
    const navigate = useNavigate()

    const [searchParams] = useSearchParams();

    const getParam = (paramName) => {
        return searchParams.get(paramName);
    };

    const account = getParam('account');
    const dwmc = getParam('dwmc');

    message.loading('系统登陆中',2, ()=>(console.log('系统登陆中')));

    autoLoginAPI({account,dwmc}).then(res => {

        message.open({
            type: res.code === 200 ? 'success' : 'error',
            content: res.message
        })
        if (res.code === 200) {
            //登陆成功，跳转到查询界面
            // navigate('/search')
            navigate("/search", { replace: true })
            localStorage.setItem('ksuser', account)
            localStorage.setItem('kshxtoken', res.data)
            localStorage.setItem('company_type', dwmc)
        }else{
            navigate('/login')
            localStorage.setItem('ksuser', null)
            localStorage.setItem('kshxtoken', null)
            localStorage.setItem('compay_type', null)
        }
    })

    return (
        <div></div>
    )
}